//求n的阶乘。至少使用递归函数完成一次。

package main

import "fmt"

//循环
func fn1(n int) (output int) {
	if n < 0 {
		panic("please input positive number")
	} else if n == 1 || n == 0 {
		return 1
	}
	output = n
	for i := n - 1; i >= 1; i-- {
		output = output * i
	}
	// fmt.Printf("%d\n", output)
	return output
}

//递归
func fn2(n int) (output int) {
	if n < 0 {
		panic("please input positive number")
	} else if n == 1 || n == 0 {
		return 1
	}
	return fn2(n-1) * n
}

func main() {
	fmt.Printf("%d的阶乘是%d\n", 11, fn1(11))
	fmt.Printf("%d的阶乘是%d\n", 11, fn2(11))
}
